//########################################################################
//## (C) by Edwin Vriethoff under Microsoft Reciprocal License (Ms-RL)  ##
//## See http://www.codeplex.com/SPUserPoll/license for full license    ##
//##                                                                    ##
//## http://edwin.vriethoff.net http://www.codeplex.com/SPUserPoll/     ##
//########################################################################

using System;
using System.Collections.Generic;
using System.Text;

namespace SPUserPoll.Business.Components
{
    public class DateAndTime
    {
        /// <summary>
        /// Checks if the datepicker value is today on poll creation which means its empty
        /// </summary>
        /// <param name="endDateValue"></param>
        /// <returns></returns>
        public static bool IsEndDateToday(DateTime endDateValue)
        {
            DateTime todayDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            DateTime endDate = new DateTime(endDateValue.Year, endDateValue.Month, endDateValue.Day, 0, 0, 0);

            if (todayDate == endDate)
                return true;
            else
                return false;
        }

        /// <summary>
        /// Checks if the poll has been expired
        /// </summary>
        /// <param name="endDateValue"></param>
        /// <returns></returns>
        public static bool IsPollExpired(DateTime endDateValue)
        {
            //Date used if no enddate is selected
            DateTime zeroDate = new DateTime(2000, 1, 1, 1, 0, 0);

            //if no end date is in use we should never expire the poll
            if (endDateValue == zeroDate)
                return false;
            
            DateTime dtToday = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
            DateTime dtPollClose = new DateTime(endDateValue.Year, endDateValue.Month, endDateValue.Day, 0, 0, 0);
            
            //If the date is today or in the past return false
            if (DateTime.Compare(dtPollClose, dtToday) < 1)
                return true;
            else
                return false;
            
        }
    }
}
